package priv.pront.code.national.acwing.dp.interval;

import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-23 19:40
 */
public class Acwing1068_环形石子合并 {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[2 * n + 1];
        int[] s = new int[2 * n + 1];
        int[][] dp = new int[2 * n + 1][2 * n + 1];
        int[][] dp2 = new int[2 * n + 1][2 * n + 1];
        for(int i = 1; i <= n; i++){
            a[i] = scanner.nextInt();
        }
        for(int i = n + 1; i <= 2 * n; i++){
            a[i] = a[i - n];
        }
        for(int i = 1; i <= 2 * n; i++){
            s[i] = s[i - 1] + a[i];
        }
        for(int len = 2; len <= n; len++){
            for(int i = 1; i + len - 1 <= 2 * n; i++){
                int j = i + len - 1;
                dp[i][j] = Integer.MAX_VALUE;
                dp2[i][j] = Integer.MIN_VALUE;
                for(int k = i; k < j; k++){
                    dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j] + s[j] - s[i - 1]);
                    dp2[i][j] = Math.max(dp2[i][j], dp2[i][k] + dp2[k + 1][j] + s[j] - s[i - 1]);
                }
            }
        }
        int INF = (int)1e9;
        int max = -INF;
        int min = INF;
        for(int i = 1; i <= n; i++){
            min = Math.min(min, dp[i][i + n - 1]);
            max = Math.max(max, dp2[i][i + n - 1]);
        }
        System.out.println(min);
        System.out.println(max);
    }
}
